﻿using System.Data.SqlClient;
using NAnt.Core.Attributes;

namespace ECM7.NantContrib.Tasks.SqlServer
{
	public abstract class BaseSqlServerTask : BaseTask
	{
		/// <summary>
		/// База данных
		/// </summary>
		[TaskAttribute("database", Required = true), StringValidator(AllowEmpty = false)]
		public string Database { get; set; }

		/// <summary>
		/// Instance
		/// </summary>
		[TaskAttribute("instance", Required = true), StringValidator(AllowEmpty = false)]
		public string Instance { get; set; }

		/// <summary>
		/// Имя пользователя
		/// </summary>
		[TaskAttribute("user", Required = false), StringValidator(AllowEmpty = false)]
		public string User { get; set; }

		/// <summary>
		/// Пароль
		/// </summary>
		[TaskAttribute("password", Required = false)]
		public string Password { get; set; }

		/// <summary>
		/// Integrated Security
		/// </summary>
		[TaskAttribute("integratedSecurity", Required = false)]
		public bool IntegratedSecurity { get; set; }

		/// <summary>
		/// Выполнение команды с логированием
		/// </summary>
		public int ExecuteCommand(SqlCommand command)
		{
			LogMessage(command.CommandText);
			return command.ExecuteNonQuery();
		}
	}
}
